#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 100;
const int M = 1e9 + 7;

int t, n;
string s;

int main()
{
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> t;
    while (t--)
    {
        cin >> n >> s;
        string t = s;
        sort(t.begin(), t.end());

        int res = 0;
        for (int i = 0; i < n; i++)
            if (s[i] != t[i])
                res++;
        cout << res << endl;
    }
    return 0;
}